package com.sznaner.tool.util;

import android.content.Context;
import android.media.AudioManager;


public class VolumeUtil {

    public static void setVolume( int volume){

        if(volume< 0) volume = 0;
        if(volume> getMaxVolume()) volume = getMaxVolume();
        AudioManager am = (AudioManager)NRTool.context().getSystemService(Context.AUDIO_SERVICE);
        am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
    }
    public static void volumeUp(){

                AudioManager am1 = (AudioManager)NRTool.context().getSystemService(Context.AUDIO_SERVICE);

                //获取系统最大音量
                int maxVolume = getMaxVolume();

                //获取当前音量
                int currentVolume1 = am1.getStreamVolume(AudioManager.STREAM_MUSIC);

                int setVolume1 = currentVolume1 + 1;

                if(setVolume1 > maxVolume) setVolume1 = maxVolume;

                //设置系统音量
                am1.setStreamVolume(AudioManager.STREAM_MUSIC, setVolume1, 0);

    }

    public static void volumeDown(){

        AudioManager am = (AudioManager)NRTool.context().getSystemService(Context.AUDIO_SERVICE);

        //获取当前音量
        int currentVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);

        int setVolume = currentVolume - 1;

        if(setVolume < 0) setVolume = 0;

        //设置系统音量
        am.setStreamVolume(AudioManager.STREAM_MUSIC, setVolume, 0);

    }

    public static int getCurVolume(){
        AudioManager am = (AudioManager)NRTool.context().getSystemService(Context.AUDIO_SERVICE);
        int currentVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
        return currentVolume;
    }

    public static int getMaxVolume(){
        AudioManager am = (AudioManager)NRTool.context().getSystemService(Context.AUDIO_SERVICE);
        //获取系统最大音量
        int maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        return maxVolume;
    }



}
